// import store from '@/store/index'
import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);

const routes = [
  {
    path: "/about",
    name: "about",
    component: () => import("@/views/AboutView.vue"),
  },
  {
    path: "/",
    name: "首页",
    component: () => import("@/views/index.vue"),
  },
  {
    path: "/index",
    name: "首页",
    component: () => import("@/views/index.vue"),
  },
  {
    path: "/index/country",
    name: "country",
    component: () => import("@/views/index/country.vue"),
  },
  {
    path: "/index/serve",
    name: "serve",
    component: () => import("@/views/index/serve.vue"),
  },
  {
    path: "/index/monitor",
    name: "monitor",
    component: () => import("@/views/index/monitor.vue"),
  },
  {
    path: "/index/doorRiver",
    name: "doorRiver",
    component: () => import("@/views/index/doorRiver.vue"),
  },
  {
    path: "/index/terrace",
    name: "terrace",
    component: () => import("@/views/index/terrace.vue"),
  },
  {
    path: "/index/dataBank",
    name: "dataBank",
    component: () => import("@/views/index/dataBank.vue"),
  },
  {
    path: "/index/taiJi",
    name: "taiJi",
    component: () => import("@/views/index/taiJi.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

//全局前置路由守卫---初始化的时候被调用、每次路由切换的时候被调用
router.beforeEach((to, from, next) => {
  /*if(from.name === null){
    store.commit('SET_SHOWBACK', true)
  }*/
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
  //这里是一个简单的例子
  //即判断用户是否进入了需要鉴权的路由下（这里距离为news和message）
  // if (to.path == '/home/message' || to.path === '/about/news') {
  //如果进入了，那就判断本地是否缓存了信息（这里模拟登录的token)
  //   if (localStorage.getItem('name') === 'haungzhizhen') {
  //     next()
  //   }
  // }else{
  //如果不是，则直接放心即可
  //   next()
  // }
});

export default router;
